<script setup>
import { ref, onMounted } from 'vue'
import { ElMessage } from 'element-plus'
import { getStudentInfo } from '../../../api/user'

const userInfo = ref({})

const fetchUserInfo = async () => {
  try {
    const data = await getStudentInfo()
    userInfo.value = data
  } catch (error) {
    ElMessage.error(error || '获取学生信息失败')
  }
}

onMounted(() => {
  fetchUserInfo()
})
</script>

<template>
  <div class="profile-container">
    <el-card class="profile-card">
      <template #header>
        <div class="card-header">
          <span class="title">个人信息</span>
        </div>
      </template>

      <div class="info-list">
        <div class="info-item">
          <span class="info-label">姓名：</span>
          <span class="info-content">{{ userInfo.name }}</span>
        </div>
        <div class="info-item">
          <span class="info-label">学号：</span>
          <span class="info-content">{{ userInfo.studentNumber }}</span>
        </div>
        <div class="info-item">
          <span class="info-label">专业：</span>
          <span class="info-content">{{ userInfo.major }}</span>
        </div>
        <div class="info-item">
          <span class="info-label">班级：</span>
          <span class="info-content">{{ userInfo.className }}</span>
        </div>
        <div class="info-item">
          <span class="info-label">性别：</span>
          <span class="info-content">{{ userInfo.gender === 0 ? '男生' : '女生' }}</span>
        </div>
        <div class="info-item">
          <span class="info-label">联系电话：</span>
          <span class="info-content">{{ userInfo.phone }}</span>
        </div>
        <div class="info-item">
          <span class="info-label">邮箱：</span>
          <span class="info-content">{{ userInfo.email }}</span>
        </div>
        <div class="info-item">
          <span class="info-label">个人简介：</span>
          <span class="info-content">{{ userInfo.userProfile }}</span>
        </div>
      </div>
    </el-card>
  </div>
</template>

<style scoped>
.profile-container {
  padding: 40px;
  background-color: #f5f7fa;
  min-height: calc(100vh - 60px);
}

.profile-card {
  max-width: 1000px;
  margin: 0 auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
}

.title {
  font-size: 24px;
  font-weight: bold;
  color: #303133;
}

.info-list {
  padding: 20px;
}

.info-item {
  display: flex;
  padding: 16px 24px;
  border-bottom: 1px solid #ebeef5;
  transition: background-color 0.3s;
}

.info-item:last-child {
  border-bottom: none;
}

.info-item:hover {
  background-color: #f5f7fa;
}

.info-label {
  width: 120px;
  color: #606266;
  font-weight: bold;
  font-size: 16px;
}

.info-content {
  flex: 1;
  color: #303133;
  font-size: 16px;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .info-item {
    padding: 12px 16px;
  }

  .info-label {
    width: 100px;
    font-size: 14px;
  }

  .info-content {
    font-size: 14px;
  }
}
</style>
